#coding=utf-8
import unittest
from appium import webdriver
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait
from Public import BaseConstant
from Public.BasePage import element_Oprate
from Public import CaseExcelOperate
import loginEgovaMobile
import settings
from Public import BasePage

#实例化变量
element_oprate_instance = element_Oprate()
Login_egova_Paramter_instances = BaseConstant.Login_egova_Paramter
excel_operate_instances = CaseExcelOperate.excel_Operate()
login_mobile_instances = loginEgovaMobile.login_factory()

class lanuch_exit_factory():

	def lanuch_app(self,driver,file_path):
		driver.launch_app()

	def login_app(self,class_name):
		user_infor = excel_operate_instances.get_userInfo(settings.test_case_file, class_name)
		if user_infor[0] != '':
			login_mobile_instances.login_system(BasePage.Base.driver,user_infor[0],user_infor[1],settings.pic_file_path)
		else:
			try:
				sleep(2)
				element_oprate_instance.element_click(Login_egova_Paramter_instances.login_btnSubmit, settings.pic_file_path)
				sleep(2)
				if element_oprate_instance.element_display_commit(Login_egova_Paramter_instances.home_tab_item_icon,settings.pic_file_path):
					print("login success.....")
					element_oprate_instance.element_save_pic(settings.pic_file_path, 'login_successful')
				else:
					print("login failed.....")

			except WebDriverException,el_error:
				element_oprate_instance.element_save_pic(settings.pic_file_path, 'login_failed')
				print el_error
				raise

	def close_app(self,driver,file_path):
		sleep(2)
		driver.close_app()

if __name__ == '__main__':
	unittest.main()
